<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="hotel.entity.*,java.util.*"%>
<%@include file="../link.html"%>
<!DOCTYPE html>
<script type="text/javascript">
$(document).ready(function() {
	$("#btn-close").click( function () { 
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭 
	});
});

function saveRole(){
	var index=$('#btn-submit').attr('class').indexOf("disabled");
	if(index==-1){//disabled的下标为-1说明确定按钮可用
		$.ajax({
	        type:"post",
	        url:"addRole",
	        data: $('#roleForm').serialize(),//表单数据
	        success: function(data){
				layer.msg('创建成功', {icon: 1, time: 800}, function(){//关闭后执行的操作
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭 
					});  
	        }
	    });
	}
	return false;
}
</script>

<div style="padding-top:30px;">
	<form id="roleForm" action="addRole" method="post" 
	data-toggle="validator" role="form" class="form-horizontal">
		<div class="form-group">
			<label class="col-sm-3 control-label">角色名称</label>
			<div class="col-sm-6">
				<input id="roleName" name="roleName" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label">说明</label>
			<div class="col-sm-6">
				<textarea id="comment" name="comment" class="form-control"></textarea>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label">权限</label>
			<div class="col-sm-6">
			<% 
				List<Authority> list=(List<Authority>)request.getAttribute("auths");
				StringBuffer buffer=new StringBuffer();
				for(Authority a:list){
					buffer.append("<div class='col-sm-6'><input type='checkbox' name='auths' class='icheckbox_minimal' value='"
					+a.getAuthorityid()+"' >"+a.getAuthorityName()+"</div>");
				}
				out.print(buffer.toString());
			%>
			</div>
		</div>
		
		<div class="box-footer"></div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label"></label>
			<div class="col-sm-6">
				<div class="pull-right">
					<button id="btn-submit" type="submit" class="btn btn-primary" onClick="return saveRole()">
						<i class="fa fa-floppy-o "></i> 确定
					</button>
					<button id="btn-close" class="btn btn-close btn-primary" type="button">
						<i class="fa fa-remove"></i> 关闭
					</button>
				</div>
			</div>
		</div>
	</form>
</div>